# check the line number of a dir. 

require "00_common"



module LineStat
  def self.get_all_files(dir)
  	all_files = Common.get_all_files(dir)
  end

  def self.stat_all_files(dir)
  	total = 0
  	all_files = get_all_files(dir)
  	all_files.each do |file_name|
  	  total = total + handle_each_file(dir, file_name)
  	end

  	total
  end

  def self.handle_each_file(dir, file_name)
  	file = File.open dir + file_name, "r"
  	counter = 0
  	begin
      while line = file.readline
        counter = counter + 1
      end
  	rescue Exception => e
  		err = e.to_s
      if err == "end of file reached"
        # nothing
      else
        puts err
      end
  	end
  	counter
  end
end

begin
  puts "http_raw: "
  puts LineStat.stat_all_files("./http_raw/")
  puts "facebook_raw: "
  puts LineStat.stat_all_files("./facebook_raw/")
  puts "facebook_payload: "
  puts LineStat.stat_all_files("./facebook_payload/")
  puts "facebook_payload_svr: "
  puts LineStat.stat_all_files("./facebook_payload_svr/")
  puts "zynga_raw: "
  puts LineStat.stat_all_files("./zynga_raw/")
  puts "dns_raw: "
  puts LineStat.stat_all_files("./dns_raw/")
rescue Exception => e
  puts e.to_s	
end